import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import './pages/home/index.dart';
import './pages/not_found.dart';
import './pages/login.dart';
import './pages/home/tab_bookstore/index.dart';
import './pages/register.dart';
import './pages/resetpassword.dart';
import './pages/noveldetail/index.dart';

class Routes {
  //1、定义路由名称
  static String home = '/';
  static String login = '/login';
  static String register = '/register';
  static String resetpassword = '/resetpassword';
  static String bookstore = '/bookstore';
  static String noveldetail = '/noveldetail/:novelId';
  //2、定义路由处理函数
  static Handler _homeHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return HomePage();
  });
  static Handler _loginHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return LoginPage();
  });
  static Handler _registerHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return RegisterPage();
  });
  static Handler _resetpasswordHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return ResetPasswordPage();
  });
  static Handler _NotFoundHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return NotFoundPage();
  });

  static Handler _bookstoreHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return TabBookStore();
  });

  static Handler _noveldetailHandler = Handler(
      handlerFunc: (BuildContext? context, Map<String, dynamic> params) {
    return NovelDetailPage(
      novelId: params['novelId'][0],
    );
  });

  //3、编写函数configureRoutes关联路由名称和处理函数
  static void configureRoutes(FluroRouter router) {
    router.define(home, handler: _homeHandler);
    router.define(login, handler: _loginHandler);
    router.define(register, handler: _registerHandler);
    router.define(resetpassword, handler: _resetpasswordHandler);
    router.notFoundHandler = _NotFoundHandler;
    router.define(bookstore, handler: _bookstoreHandler);
    router.define(noveldetail, handler: _noveldetailHandler);
  }
}
